<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>澳粒订单列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<div class="container">

    <div class="comm_content">

            <!-- 查询条件   start -->
            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>订单编号：<input type="text" class="form-control input-sm w120" name="bill_code" maxlength="20"></td>
                                <td>会 员 名：<input type="text" class="form-control input-sm w120" name="custID" maxlength="30" value="<!--{$custID|default:''}-->"></td>
                                <td>收 货 人：<input type="text" class="form-control input-sm w120" name="deliver_name" maxlength="20"></td>
                                <td>手机号码：<input type="text" class="form-control input-sm w120" name="deliver_mobile" maxlength="11"></td>
                                <td>支付状态：<select class="form-control input-sm" name="pay_status">
                                        <option value="all">请选择</option>
                                        <!--{foreach from=$global_array.pay_status item=pay_status_name key=pay_status}-->
                                        <option value="<!--{$pay_status}-->"><!--{$pay_status_name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>订单状态：<select class="form-control input-sm" name="bill_status">
                                        <option value="all">请选择</option>
                                        <!--{foreach from=$global_array.backend_bill_status item=bill_status_name key=bill_status}-->
                                            <option value="<!--{$bill_status}-->"><!--{$bill_status_name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                </td>
                                <td>支付方式：<select class="form-control input-sm" name="pay_type">
                                        <option value="">请选择</option>
                                        <option value="1">货到付款</option>
                                        <option value="2">在线支付</option>
                                    </select>
                                </td>
                                <td>订单平台：<select class="form-control input-sm" name="billPlatform">
                                        <option value="2">澳粒订单</option>
                                    </select>
                                </td>
                                <td>订单渠道：<select class="form-control input-sm" name="billChannel">
                                        <option value="all">请选择</option>
                                        <!--{foreach from=$global_array.bill_channel item=bill_channel_name key=bill_channel}-->
                                        <option value="<!--{$bill_channel}-->"><!--{$bill_channel_name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                </td>
                                <td>订单类型：<select class="form-control input-sm" name="billType">
                                        <option value="all">请选择</option>
                                        <!--{foreach from=$global_array.bill_type item=bill_type_name key=bill_type}-->
                                        <option value="<!--{$bill_type}-->"><!--{$bill_type_name.name}--></option>
                                        <!--{/foreach}-->
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>退货状态：<select class="form-control input-sm" name="withdraw_status">
                                        <option value="">请选择</option>
                                        <option value="0">未退货</option>
                                        <option value="1">部分退货</option>
                                        <option value="2">全部退货</option>
                                    </select>
                                </td>
                                <td>索要发票：<select class="form-control input-sm" name="invoice">
                                        <option value="">请选择</option>
                                        <option value="1">是</option>
                                        <option value="0">否</option>
                                    </select>
                                </td>
                                <td>是否开票：<select class="form-control input-sm" name="is_the_invoice">
                                        <option value="">请选择</option>
                                        <option value="1">是</option>
                                        <option value="0">否</option>
                                    </select>
                                </td>
                                <td colspan="2">下单日期：<input class="form-control input-sm w100" id="startDate" name="startDate" value="" readonly="readonly"   type="text" />
                                    ～
                                    <input class="form-control input-sm w100" id="endDate" name="endDate" value="" readonly="readonly" type="text" " />
                                    <button type="button" class="btn btn-default btn-sm" onclick="bill.timeClear('startDate', 'endDate');">清 空</button>
                                </td>
                            </tr>
                            <tr>
                                <td>配送日期：<input class="form-control input-sm w85" id="send_date" name="send_date" value="" readonly="readonly" type="text" />
                                    <button type="button" class="btn btn-default btn-sm" onclick="bill.timeClear('send_date');">清 空</button>
                                </td>
                                <td>城　　市：<select class="form-control input-sm" name="deliver_cityid" id="deliver_cityid">
                                        <option value="">请选择</option>
                                        <!--{if isset($city_array)}-->
                                            <!--{foreach from=$city_array item=city}-->
                                                <option value="<!--{$city.id}-->"><!--{$city.name}--></option>
                                            <!--{/foreach}-->
                                        <!--{/if}-->
                                    </select>
                                </td>
                                <td>配 送 站：<select class="form-control input-sm" name="distribution_id" id="distribution_id">
                                        <option value="">请选择</option>
                                    </select>
                                </td>
                                <td>下 单 人：<input type="text" class="form-control input-sm w120" name="creator" maxlength="20"></td>
                                <td>商　　品：<input type="text" class="form-control input-sm w120" name="goods_name_str" maxlength="20"></td>
                            </tr>
                            <tr>
                                <td>现 金 卡：<input type="text" class="form-control input-sm w120" name="card_no" maxlength="20"></td>
                                <td>优 惠 券：<input type="text" class="form-control input-sm w120" name="coupon_no" maxlength="20"></td>
                                <td colspan="2">
                                    代付订单：<input type="text" class="form-control input-sm w120" style="width: 100px" name="paying_agent_str" maxlength="20">
                                    收货地址：<input type="text" class="form-control input-sm w120" style="width: 110px" id="deliver_address_str" name="deliver_address_str" maxlength="20">
                                </td>
                                <td>
                                    <button type="button" class="btn btn-primary btn-sm" onclick="bill.search();">查 询</button>&nbsp;&nbsp;
                                    <button type="button" class="btn btn-warning btn-sm" onclick="bill.clear();">重 置</button>&nbsp;&nbsp;
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
            <!-- 查询条件   end -->

            <table id="flex" style="display:none"></table>

        </div>

    </div>

</div>

<!-- 开票 start -->
<div id="pop" style="display: none;">

    <form class="form-horizontal" id="ticketForm" onsubmit="return false;">
        <div class="form-group">
            <label for="invoice_number" class="col-sm-3 control-label"><span class="red">*</span> 发票号：</label>
            <div class="col-sm-9">
                <input type="text" class="form-control w300" id="invoice_number" name="invoice_number" maxlength="100" />
                <input type="hidden" id="bill_no" name="bill_no" value="" />
            </div>
        </div>
    </form>

</div>
<!-- 开票 end -->

<!-- 修改运费   start-->
<div id="feePaidDialog" style="display: none;">

    <input type="hidden" id="feePaid_hidd_bill_no" value=""/>
    <input type="hidden" id="feePaid_hidd_bill_code" value=""/>
    <input type="hidden" id="feePaid_hidd_deliver_feePaid" value=""/>
    <div class="form-group">
        <label class="col-sm-3 control-label"> 订单编号：</label>
        <div class="col-sm-9">
            <label id="feePaid_bill_code" class="col-sm-3 control-label"></label>
        </div>

        <label class="col-sm-3 control-label" style="margin-top: 8px;"> 修改运费：</label>
        <div class="col-sm-9">
            <input type="text" class="form-control w150" style="display: inline-block;" id="deliver_feePaid" onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" />
        </div>

        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <span id="feePaid_message"></span>
        </div>

    </div>

</div>
<!-- 修改运费   end-->


<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/bill/billSearch.ajax?operFlg=1&is_al=1",
        dataType: "json",
        colModel : [
            {display: "操作", width : 200, align: "center"},
            {display: "订单编号", name : "bill_no", width : 260, sortable : true, align: "center"},
            {display: "订单类型", width : 100},
            {display: "订单状态", width : 80},
            {display: "订单标识", width : 80},
            {display: "支付方式", width : 120},
            {display: "代付订单号", width : 200},
            {display: "到货时间", width : 200},
            {display: "下单时间", width : 140, align: "center"},
            {display: "商品明细", width : 300},
            {display: "商品数量", width : 80},
            {display: "餐具数量", width : 80},
            {display: "蜡烛数量", width : 80},
            {display: "订单金额", width : 80},
            {display: "应收金额", width : 80},
            {display: "已收金额", width : 80},
            {display: "调价金额", width : 80},
            //add by allen.qiang 20141110 FUN-BK-0022-配送部自购业务需求 --start
            {display: "退货金额", width : 80},
            {display: "配送自购金额", width : 100},
            //add by allen.qiang 20141110 FUN-BK-0022-配送部自购业务需求 --end
            {display: "服务费", width : 60},
            {display: "城市", width : 80},
            {display: "区", width : 80},
            {display: "配送站", width : 120},
            {display: "配送员", width : 120},
            {display: "配送员手机", width : 120},
            {display: "收货人手机号码", width : 120, align: "center"},
            {display: "收货人", width : 120},
            {display: "创建人", width : 120},
            {display: "退货状态", width : 100},
            {display: "发票类型", width : 100},
            {display: "抬头类型", width : 100},
            {display: "发票抬头", width : 100},
            {display: "发票金额", width : 100},
            {display: "发票内容", width : 100},
            {display: "发 票 号", width : 100}
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加订单", bclass: "add", onpress : "bill.add"}
        ],
        <!--{/if}-->
        sortname: "bill_no",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        autoload: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    /**
     * 订单操作类
     */
    var bill = {

        //查询
        search: function() {
            if($('#deliver_address_str').val().length < 4 && $('#deliver_address_str').val().length >0){
                E.alert('地址条件必须满4个字符');
                $('#deliver_address_str').select();
                $('#deliver_address_str').focus();
                return;
            }
            var dt = $("#search_form").serializeArray();
            $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
        },

        //重置
        clear: function() {
            document.getElementById('search_form').reset();
            this.search();
        },

        //清空
        timeClear:function(){
            for(var i=0; i<arguments.length; i++){
                var id = arguments[i];
                $('#'+id).val('');
            }
        },

        //添加订单
        add: function() {
            self.location = '/quanliadmin/app/callcenter/callcenter.pscript?operFlg=1&billPlatform=2';
        },

        //修改订单
        AL_alter: function(bill_no) {
            window.open('/quanliadmin/app/bill/billEdit.pscript?operFlg=5&bill_no=' + bill_no);
        },

        //取消订单
        cancel: function( bill_no ) {
            this.bill_no = bill_no;
            E.confirm("您确认取消该订单吗？", "bill.confirmCancel");
        },

        confirmCancel: function() {
            E.ajax_get({
                url: "/invokingAjax-backend/bill/bill.ajax?operFlg=4",
                data: {
                    bill_no: this.bill_no
                },
                call: "bill.result"
            });
        },

        //退货
        returnGoods : function( bill_no ) {
            window.open("/quanliadmin/app/bill/billReturn.pscript?operFlg=2&bill_no=" + bill_no);
        },

        //开票
        makeTicket: function( bill_no ){
            $('#bill_no').val(bill_no);
            E.popup.open({
                id:"pop",
                title: "开发票",
                css: "width:800px;",
                btnName: "保存",
                btnCall:"bill.check();"
            });
        },

        //验证发票
        check: function(){
            this.dt = E.getFormValues("ticketForm");
            var invoice_number = $.trim( $("#invoice_number").val() );
            var err_msg = '';

            if(invoice_number == ''){
                err_msg += '发票号不能为空，请填写<br />';
            }

            if(err_msg != ''){
                E.alert(err_msg);
            }else{
                bill.execute();
            }
        },

        //开票执行
        execute: function(){
            E.popup.close();
            E.loadding.open("正在保存，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/bill/billSearch.ajax?operFlg=100",
                data: this.dt,
                call: "bill.result"
            });
        },

        //返回结果
        result:function(o){
            if (o.code == 200) {
                E.alert(o.message, 2, "bill.load");
            } else {
                E.alert(o.message);
            }
            E.loadding.close();
        },

        //刷新表格
        load: function() {
            $("#flex").flexReload();
        },

        //下车，出仓状态修改运费
        showFeePaidDialog: function(bill_no,bill_code,deliver_feePaid){

            $("#feePaid_message").html("");
            $("#feePaid_hidd_bill_no").val(bill_no);
            $("#feePaid_hidd_bill_code").val(bill_code);
            $("#feePaid_bill_code").text(bill_code);
            $("#feePaid_hidd_deliver_feePaid").val(deliver_feePaid);

            //调用打开弹出层公共JS方法
            E.popup.open({
                id:"feePaidDialog",   		 //获取id为"feePaidDialog"元素内的HTML
                title: "修改运费",       //弹出层标题
                css: "width:600px;",     //设置弹出层样式
                btnName: "提交",         //执行“确定”操作的按钮名称
                btnCall:"bill.upfeePaid();"  //点击确定后执行的方法
            });

            $("#deliver_feePaid").val(deliver_feePaid);

        },

        //修改运费
        upfeePaid:function(){
            if($("#deliver_feePaid").val()==""){
                E.alert("请输入运费金额");
                $("#deliver_feePaid").focus();
                return;
            }else if($("#feePaid_hidd_deliver_feePaid").val()==$("#deliver_feePaid").val()){
                E.alert("请修改运费金额");
                $("#deliver_feePaid").focus();
                return;
            }else if( parseFloat($("#deliver_feePaid").val())< 0){
                E.alert("运费金额不能为负数");
                $("#deliver_feePaid").focus();
                return;
            }
            E.confirm("您确认修改此订单的运费吗？", "bill.confirmFeePaid");
        },

        confirmFeePaid:function(){
            var bill_no= $("#feePaid_hidd_bill_no").val();
            var deliver_feePaid=$("#deliver_feePaid").val();
            E.loadding.open('正在修改运费...');
            E.ajax_post({
                url: '/invokingAjax-backend/bill/bill.ajax?operFlg=8',
                data: {
                    deliver_feePaid:deliver_feePaid,
                    bill_no: bill_no
                },
                call: "bill.useFeePaidResult(o);"
            });
        },

        useFeePaidResult:function(o){
            E.loadding.close();
            if(o.code==200){
                E.popup.close();
                bill.load();
                E.alert("运费修改成功!", 2 ,"");
            }else{
                bill.load();
                E.alert(o.message);
            }
        },

        //下车
        debus:function(bill_no){

            this.bill_no = bill_no;

            E.confirm("您确认执行下车操作吗？", "bill.excuteDebus");

        },

        excuteDebus:function(){

            E.loadding.open('正在下车中，请稍后...');
            E.ajax_post({
                url: '/invokingAjax-backend/bill/bill.ajax?operFlg=9',
                data: {
                    bill_no: this.bill_no
                },
                call:function(o){
                    E.loadding.close();
                    if(o.code == 200){
                        bill.load();
                        E.alert(o.message, 2, '');
                    }else{
                        E.alert(o.message);
                    }
                }
            });
        }

    };

    $('#startDate').datepicker();
    $('#endDate').datepicker();
    $('#send_date').datepicker();

    $(function() {

        //配送站根据城市改变联动
        $('#deliver_cityid').change(function() {
            var deliver_cityid = $(this).val();
            if (deliver_cityid == '') {
                $('#distribution_id').html('<option value="">请选择</option>');
            } else {
                E.ajax_get({
                    url: '/invokingAjax-comm/bill/distribution.ajax?operFlg=2',
                    data: {
                        deliver_cityid: deliver_cityid,
                        no_act: 1
                    },
                    call: function( o ) {
                        $('#distribution_id').html('<option value="">请选择</option>');
                        if (o.data) {
                            $.each(o.data, function(k, v) {
                                $('#distribution_id').append('<option value="' + v.distribution_id + '">' + v.distribution_name + '</option>');
                            });
                        }
                    }
                });
            }
        });

    });

</script>

</body>
</html>